<?php
/**
 * 用户表数据操作层
 * @author yangchao
 * @package user
 * @copyright yangchao
 * @version 1.0
 * @code-encode utf-8
 * @data-encode 2011-01-17
 */


define("CACHE_PREFIX_MBLOG_USER_LOVE","mblog_user_love_");


class db_mblog_user_love extends db_base {
    
	var $table_name = "mblog_user_love";
	
	function db_mblog_user_love()
	{
		parent::db_base();
	}
	
	
	
	
	
	function get_mblog_user_love_count_by_mblog_id($mblog_id)
	{
		$mblog_id = intval($mblog_id);
		$mc = mem_cache::get_instance();
		$key = CACHE_PREFIX_MBLOG_USER_LOVE."-get_mblog_user_love_count_by_mblog_id-{$mblog_id}";
		$cache = $mc->get($key);
		if ($cache === false)
		{
			$content = $this->get_listcount($this->table_name,"mblog_id = $mblog_id and status=1");
			// 保存MC
			$mc->set($key, serialize($content), 0, CACHE_EXPIRE_MIN_5);
		}
		else
		{
			$content = unserialize($cache);
		}
		
		return $content[0];
		
	}
	
	
	
	function get_mblog_user_love_count_by_uid($uid="")
	{
		$uid = intval($uid);
		
		$mc = mem_cache::get_instance();
		$key = CACHE_PREFIX_USER_ITEM."-get_mblog_user_love_count_by_uid-{$uid}";
		$cache = $mc->get($key);
		if ($cache === false)
		{
			$where_ary = array();;
			if(strlen($uid)>0)
			{
				$where_ary[] = "uid = {$uid}";
				
			}
			$where_ary[] = "status = 1";
			
			$where = join(" and ",$where_ary);
			$content = $this->get_listcount($this->table_name,$where);
			// 保存MC
			$mc->set($key, serialize($content), 0, CACHE_EXPIRE_MIN_5);
		}
		else
		{
			$content = unserialize($cache);
		}
		
		return $content;
		
	}
	
	
	function get_mblog_user_love_list_by_uid($uid="",$p=1,$pcount=5)
	{
		$uid = intval($uid);
		$p = intval($p);
		$pcount = intval($pcount);
		
		$mc = mem_cache::get_instance();
		$key = CACHE_PREFIX_USER_ITEM."-get_mblog_user_love_list_by_uid-{$uid}-{$p}-{$pcount}";
		$cache = $mc->get($key);
		if ($cache === false)
		{
			$where_ary = array();;
			if(strlen($uid)>0)
			{
				$where_ary[] = "uid = {$uid}";
				
			}
			$where_ary[] = "status = 1";
			
			$where = join(" and ",$where_ary);
			$content = $this->get_alllist($this->table_name,$p,$pcount,"",$where);
			// 保存MC
			$mc->set($key, serialize($content), 0, CACHE_EXPIRE_MIN_5);
		}
		else
		{
			$content = unserialize($cache);
		}
		
		return $content;
		
	}
	
	
	function get_mblog_user_love_content_list_by_uid($uid="",$p=1,$pcount=20)
	{
		$uid = intval($uid);
		$p = intval($p);
		$pcount = intval($pcount);
		
		$start = ($p-1)*$pcount;
		$sql ="select B.* from mblog_user_love A left join mblog_pic_content B on A.mblog_id = B.id where A.uid=$uid and A.status = 1 and B.status =1 limit $start,$pcount";
		$result = $this->select($sql);
		return $result;
		
	}

	
	function insert_mblog_user_love($mblog_id,$uid,$crc32_key)
	{
		// 插入数据
		$ary = array();

		if(strlen($topic)>0)$ary["topic"] = $topic;
		$ary["status"] = 1;
		$ary["mblog_id"] = $mblog_id;
		
		$ary["crc32_key"] = $crc32_key;
		$ary["create_ip"] = IP::get_client_ip_long();
		$ary["uid"] = $uid;
		
		$ret = $this->insert($this->table_name, $ary);
		

		return $ret;
	}
	
	function update_mblog_user_love_by_uid_and_mblog_id($mblog_id,$uid,$status)
	{
		
		$mblog_id = intval($mblog_id);
		$uid = intval($uid);
		
		
		$where = "mblog_id = $mblog_id and uid = $uid";
		
		if(strlen($status)>0)$ary["status"] = $status;
		
		
		return $this->update($this->table_name, $ary,$where);
	}
	
	####################后台程序
	
	

	
	
	


}



